package com.example.dqnm.controller;

import com.example.dqnm.pojo.Shippingaddress;
import com.example.dqnm.pojo.UserAddress;
import com.example.dqnm.pojo.ajaxResult;
import com.example.dqnm.service.ShippingaddressService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequiredArgsConstructor
@RestController
@RequestMapping("/Shippingaddress")
public class ShippingaddressController {
    @Autowired
    private ShippingaddressService shippingaddressService;

    @GetMapping("/getUserAddress")
    public ajaxResult<List<Shippingaddress>> selectAllShippingaddress(Integer id) {
        List<Shippingaddress> array = shippingaddressService.selectAllShippingaddress(id);
        return new ajaxResult<>(array);
    }

    @PostMapping("/addUserAddress")
    public ajaxResult<Boolean> addUserAddress(@RequestBody Shippingaddress shippingaddress) {
//        System.out.println(shippingaddress);
        Boolean flag = shippingaddressService.addUserAddress(shippingaddress);
        return new ajaxResult<>(flag);
    }

    @DeleteMapping("/deleteUserAddress")
    public ajaxResult<Boolean> deleteUserAddress(@RequestParam ("id") Integer id) {
        Boolean flag = shippingaddressService.deleteUserAddress(id);
        return new ajaxResult<>(flag);
    }

    @PutMapping("/updateUserAddress")
    public ajaxResult<Boolean> updateUserAddress(@RequestBody Shippingaddress shippingaddress) {
        Boolean flag = shippingaddressService.updateUserAddress(shippingaddress);
        return new ajaxResult<>(flag);
    }
}
